
import numpy as np



def f_数据转_vec3_1D(data, 维度=3):
	a = np.array(data)
	#print('a == ', a, data, a.ndim)
	if a.ndim == 0:
		newData = np.ndarray((1, 维度))
		newData[:, :] = data
		data = newData
	elif a.ndim == 1:
		newData = np.ndarray((a.shape[0], 3))
		if a.shape[0] != 维度:
			newData[:, :] = data[0]
			#newData = newData.reshape((3, a.shape[0]))
			#print('newData B = ', newData)
		else:
			newData[:, :] = data
		#data = newData
	elif a.ndim == 2:
		newData = data
		
	return newData




def f_数据转_vec_2D(data, 维度=3):
	a = np.array(data)
	#print('a == ', a, data, a.ndim)
	if a.ndim == 0:
		newData = np.ndarray((1, 1, 维度))
		newData[:, :, :] = data
		data = newData
	elif a.ndim == 1:
		newData = np.ndarray((1, a.shape[0], 3))
		if a.shape[0] < 维度:
			newData[:, :, :] = data[0]
		else:
			newData[:, :, :] = data[:3]
	elif a.ndim == 2:
		newData = np.ndarray((a.shape[1], a.shape[2], 3))
		if a.shape[1] < 维度:
			newData[:, :, :] = data[:, 0]
		else:
			newData[:, :, :] = data[:, :3]
	elif a.ndim == 3:
		print('a.shape = ', a.shape)
		newData = np.ndarray((a.shape[0], a.shape[1], 3))
		临时Data = np.reshape(data, (-1, a.shape[1], a.shape[2]))
		if a.shape[2] < 维度:
			newData[:, :, :] = 临时Data[:, :, 0]
		else:
			newData[:, :, :] = 临时Data[:, :, :3]
	
	return newData







def f_get数组长度(data):
	try:
		return len(data)
	except :
		return -1

def f_维度转换_vec_2D_任意维度(data, 维度=3):
	y = f_get数组长度(data)
	if y != -1:
		pass
		
	a = np.array(data)
	#print('a == ', a, data, a.ndim)
	if a.ndim == 0:
		newData = np.ndarray((1, 1, 维度))
		newData[:, :, :] = data
		data = newData
	elif a.ndim == 1:
		newData = np.ndarray((1, a.shape[0], 3))
		if a.shape[0] < 维度:
			newData[:, :, :] = data[0]
		else:
			newData[:, :, :] = data[:3]
	elif a.ndim == 2:
		newData = np.ndarray((a.shape[1], a.shape[2], 3))
		if a.shape[1] < 维度:
			newData[:, :, :] = data[:, 0]
		else:
			newData[:, :, :] = data[:, :3]
	elif a.ndim == 3:
		print('a.shape = ', a.shape)
		newData = np.ndarray((a.shape[0], a.shape[1], 3))
		临时Data = np.reshape(data, (-1, a.shape[1], a.shape[2]))
		if a.shape[2] < 维度:
			newData[:, :, :] = 临时Data[:, :, 0]
		else:
			newData[:, :, :] = 临时Data[:, :, :3]
	
	return newData

